<?php

namespace App\model\panyuan;

use Illuminate\Database\Eloquent\Model;

/**
 * App\model\panyuan\UserShenheSum
 *
 * @property int $id
 * @property int|null $user_id
 * @property int|null $num
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum whereNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\panyuan\UserShenheSum whereUserId($value)
 * @mixin \Eloquent
 */
class UserShenheSum extends Model
{
    protected  $table='user_shenhe_sum';
    static function addSum($user_id){
       $sum= self::where('user_id',$user_id)->first();
       if (!$sum){
           $sum=new self();
           $sum->user_id=$user_id;
           $sum->save();
       }
       $sum->increment('num',1);
    }
    static function delSum($user_id){
       $sum= self::where('user_id',$user_id)->first();

       if ($sum){
           if ($sum->num>0){
               $sum->decrement('num',1);
           }

       }

    }
}
